﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace APJunktion.ATP.PacketConverter
{
    public class NoControlCharString
    {
        private readonly string value;

        public NoControlCharString(string s)
        {

            if (s == null || s.Trim().Length == 0)
            {
                this.value = s;
                return;
            }

            StringBuilder stringBuilder = new StringBuilder(s.Length);

            foreach (char currentChar in s)
            {

                if ("\n\t\r".Contains(currentChar) ||
                   (currentChar != 127 && currentChar > 31))
                {
                    stringBuilder.Append(currentChar);
                }
            }

            this.value = stringBuilder.ToString();
        }

        public override string ToString()
        {
            return this.value;
        }
    }
}
